/******************************************************************************
*
*               Copyright Mentor Graphics Corporation 2003
*                           All rights reserved
*
*   THIS WORK CONTAINS TRADE SECRETS AND PROPRIETARY INFORMATION WHICH IS
*    THE PROPERTY OF MENTOR GRAPHICS CORPORATION OR ITS LICENSORS AND IS
*                        SUBJECT TO LICENSE TERMS
*
*******************************************************************************

*******************************************************************************
* FILE NAME                                                          VERSION
* act_scope_rules_test.c                                               1.1
*
* COMPONENT
* ANSI/ISO C test application
*
* DESCRIPTION
* Contains tests for scope of variables (local and global)
*
* DATA STRUCTURES
*
*
* FUNCTIONS
* int scope_test_function1(int value)
* int scope_test_function2(int value)
* int scope_test_function3(int value)
* int act_scope_rules_test(int value)
*
* DEPENDENCIES
* act_test.h
******************************************************************************/

#include "act_test.h"

#if ACT_SCOPE_RULES_TEST

int variable = 1;                               /* Global variable */

/******************************************************************************
* FUNCTION
* int scope_test_function1(int value)
*
* DESCRIPTION
* Performs scope test on local and global variables
*
* INPUTS
* int value
*
* OUTPUTS
* int
*
******************************************************************************/
int scope_test_function1(int value)
{
     int test=value;
     int result=0;

     test = variable;                                    /* test better be 1 */
     result += test;
    
     if (test)
     {
          int variable = 2;
          int anotherLocalVariable;
          
          test = variable;                                /* test better be 2 */
          anotherLocalVariable = result + test;
          result = anotherLocalVariable;
          
          if (test)
          {
               int variable = 3;
               int anInnerVariable;
               
               test = variable;                            /* test better be 3 */
               anInnerVariable = test + result;
               result = anInnerVariable;
          }
        
          test = variable;                                 /* test better be 2 */
          result += test;
     }
     
     test = variable;                                     /* test better be 1 */
     result += test;
     return result;
}


/******************************************************************************
* FUNCTION
* int scope_test_function2(int value)
*
* DESCRIPTION
* Performs scope test on global variable
*
* INPUTS
* int value
*
* OUTPUTS
* int
*
******************************************************************************/
int scope_test_function2(int value)
{
     int test = variable; /*  better be 1 */
     return test;
}


/******************************************************************************
* FUNCTION
* int scope_test_function3(int value)
*
* DESCRIPTION
* Performs lifetime of variables in different scopes
*
* INPUTS
* int value
*
* OUTPUTS
* int
*
******************************************************************************/
int scope_test_function3(int value)
{
     int testVariable = (value % 2);

     if (testVariable)
     {
          int limited_scope_variable;

          limited_scope_variable = variable + 5;
		  variable = limited_scope_variable;

                
     }

        /*  limited_scope_variable is no longer in scope.  */

     testVariable = value % 1;

     if (testVariable)
     {
          int limited_scope_variable;

          limited_scope_variable = variable + 10;
		  variable = limited_scope_variable;

     }

     return testVariable;
}


/******************************************************************************
* FUNCTION
* int act_scope_rules_test(int value)
*
* DESCRIPTION
* Calls the scope test functions (scope_test_function1-3)
*
* INPUTS
* int value
*
* OUTPUTS
* int
*
******************************************************************************/
int act_scope_rules_test(int value)
{
     value = scope_test_function1(value);

     value = scope_test_function2(value);

     value = scope_test_function3(value);

     return value;
}

#endif
